package com.yjhb.android.sbz.adapter.taskmanage;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.ManagerTask;
import com.yjhb.android.sbz.enums.TaskState;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

/**
 * 创建者 zx
 * 创建时间 2020/12/9 10:47
 */
public class TaskManagerCommonAdapter extends BaseRecyclerAdapter<TaskManagerCommonAdapter.TaskManagerCommonHolder, ManagerTask> {
    private final String TAG = "WaitAdapter";

    public TaskManagerCommonAdapter(Context context) {
        super(context);
    }

    @Override
    protected TaskManagerCommonHolder getHolder(View v) {
        return new TaskManagerCommonHolder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_task_manager_common;
    }

    @Override
    public void onBindViewHolder(@NonNull TaskManagerCommonHolder taskManagerCommonHolder, int i) {
        taskManagerCommonHolder.name_tv.setText(entity.getTask().getName());

        taskManagerCommonHolder.money_tv.setText("（" + entity.getTask().getMoney() + "元）");
        switch (TaskState.getState(entity.getTask().getState())){
            case TASK_STATE_WAIT:
                taskManagerCommonHolder.state_tv.setText("审核中");
                taskManagerCommonHolder.state_tv.setBackgroundColor(context.getResources().getColor(R.color.red_3b));
                break;
            case TASK_STATE_OFF:
                taskManagerCommonHolder.state_tv.setText("已下架");
                taskManagerCommonHolder.state_tv.setBackgroundColor(context.getResources().getColor(R.color.gray_c0));
                break;
            case TASK_STATE_VIOLATION:
                taskManagerCommonHolder.state_tv.setText("已下架");
                taskManagerCommonHolder.state_tv.setBackgroundColor(context.getResources().getColor(R.color.gray_c0));
                String depict = entity.getTask().getRejectReason();
                if (TextUtils.isEmpty(depict)){
                    depict = "";
                }
                taskManagerCommonHolder.depict_tv.setText(depict);
                break;
        }
    }

    class TaskManagerCommonHolder extends RecyclerView.ViewHolder {

        TextView name_tv;
        TextView money_tv;
        TextView depict_tv;
        TextView state_tv;

        public TaskManagerCommonHolder(@NonNull View itemView) {
            super(itemView);
            name_tv = itemView.findViewById(R.id.name_tv);
            money_tv = itemView.findViewById(R.id.money_tv);
            depict_tv = itemView.findViewById(R.id.depict_tv);
            state_tv = itemView.findViewById(R.id.state_tv);
        }
    }

}
